﻿using MediatR;
using SmartMedicalCare.API.Read.Applications.Commands.科室;
using SmartMedicalCare.API.Read.DTO.科室DTO;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;

namespace SmartMedicalCare.API.Read.Applications.CommandHandlers.科室
{
    public class QuerySelectCommandHandler : IRequestHandler<QuerySelectCommand, APIResult<List<SelectDTO>>>
    {
        private readonly IBaseRespository<DepartmentModel> departRep;
        private readonly IBaseRespository<DeptSubCategoryModel> depsubRep;

        public QuerySelectCommandHandler(IBaseRespository<DepartmentModel> departRep, IBaseRespository<DeptSubCategoryModel> depsubRep)
        {
            this.departRep = departRep;
            this.depsubRep = depsubRep;
        }

        public Task<APIResult<List<SelectDTO>>> Handle(QuerySelectCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SelectDTO>> result=new APIResult<List<SelectDTO>>();
            result.code=ResultCode.显示成功;
            result.Message=ResultCode.显示成功.ToString();

            var res = from a in departRep.GetAll()
                      //join b in depsubRep.GetAll() on a.DepartmentId equals b.DepartmentId
                      select new SelectDTO
                      {
                          DepartmentId = a.DepartmentId,
                          Name = a.Name,
                          //DeptSubCategoryId = b.DeptSubCategoryId,
                          //Name2 = b.Name

                      };
            result.Data = res.ToList();

            return Task.FromResult(result);
        
        }
    }
}
